package com.antifly.common.dao.impl;

import com.antifly.common.dao.SysDictItemDao;
import com.antifly.common.dao.mapper.SysDictItemMapper;
import com.antifly.common.pojo.entity.SysDictItemDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 数据字典项表(SysDictItem)Dao接口实现
 *
 * @author makejava
 * @date 2023-04-25
 */
@Component
public class SysDictItemDaoImpl extends ServiceImpl<SysDictItemMapper, SysDictItemDO> implements SysDictItemDao {

    @Autowired
    private SysDictItemMapper sysDictItemMapper;

    /**
     * 分页查询数据字典项表信息
     *
     * @param key      搜索关键字
     * @param pageNum  当前页码
     * @param pageSize 每页展示数 当值为-1时默认展示全部
     * @return
     */
    @Override
    public Page<SysDictItemDO> selectSysDictItemList(String key, Integer pageNum, Integer pageSize) {
        Page<SysDictItemDO> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SysDictItemDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(SysDictItemDO::getCreatedTime);
        return sysDictItemMapper.selectPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<SysDictItemDO> selectSysDictItemList() {
        LambdaQueryWrapper<SysDictItemDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(SysDictItemDO::getCreatedTime);
        return sysDictItemMapper.selectList(lambdaQueryWrapper);
    }

    /**
     * 查询所有数据字典项表信息
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> selectMaps() {
        return sysDictItemMapper.selectMaps(null);
    }

    /**
     * 根据id查询数据字典项表信息
     *
     * @param id 主键ID
     * @return
     */
    @Override
    public SysDictItemDO selectSysDictItemById(String id) {
        return sysDictItemMapper.selectById(id);
    }

    @Override
    public String insertSysDictItem(SysDictItemDO sysDictItemDO) {
        sysDictItemMapper.insert(sysDictItemDO);
        return sysDictItemDO.getId();
    }

    @Override
    public Boolean updateSysDictItem(SysDictItemDO sysDictItemDO) {
        int rows = sysDictItemMapper.updateById(sysDictItemDO);
        return rows > 0;
    }

    @Override
    public Boolean deleteSysDictItem(String sysDictItemId) {
        int rows = sysDictItemMapper.deleteById(sysDictItemId);
        return rows > 0;
    }

}